<%@ page import="org.apache.catalina.ant.ServerinfoTask" %>
<%@ page import="java.io.File" %>
<%@ page import="WebHard.Servlet_login" %>
<%@ page import="WebHard.Servlet_fileview" %>
<%@ page import="java.net.URLDecoder" %>
<%--
  Created by IntelliJ IDEA.
  User: RaysMac
  Date: 14. 12. 16.
  Time: 오전 7:56
  To change this template use File | Settings | File Templates.
--%>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
  <title>나의 폴더</title>
</head>
<body>
<h1>폴더 리스트</h1>
<form action="/user/logout" method="post">
  <input type="submit" value="로그아웃"/>
</form>

<%

  String uri  = request.getRequestURI();
  uri= URLDecoder.decode(uri);  //한글이 자동 인코딩 되기에 필요.
  uri=uri.replaceAll("/me",""); // 다운로드를 <a href 방식으로 하기에 붙여준 주소
  String now=Servlet_login.root+uri;
  //String rootpath=Servlet_login.root.substring(88,Servlet_login.root.length());
  //application.setAttribute("now", Servlet_login.root);
  File root=new File(now);
  request.setAttribute("now",now);
  application.setAttribute("now",now);

%>

<table>
  <td>
    <tr>
      <form action="/user/mkdir" method="post">
        <input type="hidden" name="nowdir" value=<%=now%> />
        <input type="text" name="fldrname" />
        <input type="submit" value="폴더생성"/>
      </form>


    </tr>
    <tr>
      <form action="/user/deldir" method="post">
        <input type="hidden" name="nowdir" value=<%=now%> />
        <select name="delforder">
          <option value="">삭제할 폴더 선택</option>
          <%
            for(String s : root.list()) {

              File child = new File(root.getPath() + "/" + s);
              if (child.isDirectory())
              {
          %>
          <option value=<%=s%>><%=s%></option>

          <%
              }
            }
          %>
        </select>
        <input type="submit" value="폴더삭제"/>
      </form>
    </tr>
    <tr>
      <form method="POST" ENCTYPE="multipart/form-data" action="/upload">
        <table width="500" border="1" align="center" bgcolor="dddddd">
                  <tr>
                          <td width="400" colspan="2" align="center"><b>파일 업로드 기능</b></td>
                  </tr>
                  <tr>
                          <td width="100" align="center">파일명</td>
                          <td width="300"> <input type="file" name="upfile" size="20"><br/>(파일의 용량 제한 : 20M)</td>
                  </tr>
                  <tr>
                          <td align="center" colspan="2">
                                  <input type="submit" value="전송"> <input type="reset" value="취소">
                          </td>
                  </tr>
        </table>
      </form>


    </tr>


  </td>


</table>
<br/>
<%=Servlet_login.root%><br/><br/>

<br/>

<a href="/me/">..</a><br/>

<%
  //root.list();
  for(String s : root.list())
  {
%>
<%
  //s = s.replaceAll("\u0020", "&nbsp;");
  File child =new File(root.getPath()+"/"+s);
  if(child.isDirectory())
  {
    if(uri.equals("/"))
      s="/"+s;
    else
      s=uri+"/"+s;

%>

<a href="/me<%=s%>"><%=s%></a><br/>
<%
}

else if(child.isHidden())
{
  continue;
}


else
{
  String fileAd=child.getAbsolutePath();
%>
<a href="<%=fileAd.substring(88,fileAd.length())%>"> <%=s%></a><br/>
<%
    }
  }
%>



</body>
</html>
